package com.xjk.demo.entity;

public class GoodsParam {

  private String keyword; // 查询关键字

  private Integer cpage = 1; // 当前页

  private Integer pageSize = 2; // 每页显示数量

  private Integer offset; // 起始条数

  private Integer prePage;// 上一页

  private Integer nextPage; // 下一页

  private Integer fistPage;// 首页

  private Integer lastPage;// 尾页

  private Integer totalPage;// 总页数

  private Integer total;// 总条数

  private String pageUrl;

  public String getKeyword() {

    return keyword;

  }

  public void setKeyword(String keyword) {

    this.keyword = keyword;

  }

  public Integer getCpage() {

    return cpage;

  }

  public void setCpage(Integer cpage) {

    this.cpage = cpage;

  }

  public Integer getPageSize() {

    return pageSize;

  }

  public void setPageSize(Integer pageSize) {

    this.pageSize = pageSize;

  }

  public Integer getOffset() {

    offset = (getCpage() - 1) * getPageSize();

    return offset;

  }

  public void setOffset(Integer offset) {

    this.offset = offset;

  }

  public Integer getPrePage() {

    return cpage <= 1 ? 1 : cpage - 1;

  }

  public void setPrePage(Integer prePage) {

    this.prePage = prePage;

  }

  public Integer getNextPage() {

    return cpage >= getTotalPage() ? getTotalPage() : cpage + 1;

  }

  public void setNextPage(Integer nextPage) {

    this.nextPage = nextPage;

  }

  public Integer getFistPage() {

    return 1;

  }

  public void setFistPage(Integer fistPage) {

    this.fistPage = fistPage;

  }

  public Integer getLastPage() {

    return getTotalPage();

  }

  public void setLastPage(Integer lastPage) {

    this.lastPage = lastPage;

  }

  public Integer getTotalPage() {

    return getTotal() % getPageSize() == 0 ? getTotal() / getPageSize() : getTotal() / getPageSize() + 1;

  }

  public void setTotalPage(Integer totalPage) {

    this.totalPage = totalPage;

  }

  public Integer getTotal() {

    return total;

  }

  public void setTotal(Integer total) {

    this.total = total;

  }

  public String getPageUrl() {

    pageUrl = "<a href='javascript:void(0)' onclick='fenye(1)'>首页</a>"

    + "<a href='javascript:void(0)' onclick='fenye(" + getPrePage() + ")'>上一页</a>"

    + "<a href='javascript:void(0)' onclick='fenye(" + getNextPage() + ")'>下一页</a>"

    + "<a href='javascript:void(0)' onclick='fenye(" + getLastPage() + ")'>末页</a>"

    + " 第" + getCpage() + " / " + getTotalPage() + "页 共" + getTotal() + "条";

    return pageUrl;

  }

  public void setPageUrl(String pageUrl) {

    this.pageUrl = pageUrl;

  }

  /*
   * 
  //添加

  @RequestMapping("/toadd")
  public String toadd(Student s) {
    System.out.println(s.getHid());
    String exhName = "springrabbit_exg";
    String routingKey = "direct";
    sendMsg.sendObject(exhName, routingKey, s);
    return "redirect:/student/list";

  }
  
 @Transactional
@Service("msgProcess")
public class StudentServiceImpl implements StudentService, IMsgProcess {

  @Autowired
  private StudentMapper studentMapper;

  // 向rabbitmq发送数据
  @Override
  public Object processMsg(Object obj) {
    // TODO Auto-generated method stub
    if (obj instanceof Student) {
      Student s = (Student) obj;
      System.out.println(s.getHid());
      studentMapper.toadd(s);
      studentMapper.add(s);
    }
    return null;
  }

select s.*,GROUP_CONCAT(h.hname) hob from z_student s left join z_s2h t on s.id=t.sid left join z_hobby h on t.hid=h.hid 
	group by s.name limit #{offset},#{pageSize}
  
<insert id="toadd">
	insert into z_student set id=#{id},name=#{name}
</insert>

<insert id="add">
	insert into z_s2h(id,sid,hid)  values
	<foreach collection="hid" item="hid" separator=","> 
		(null,#{id},#{hid})
	</foreach>
</insert>

  select s.*,GROUP_CONCAT(h.hname) hob from z_student s left join z_s2h t on s.id = t.sid left join z_hobby h
	on t.hid = h.hid where s.name like '%${keyword}%'  group by s.name limit #{offset},#{pageSize}
  *
  
  
  
  
  //  登陆
  @ResponseBody
  @RequestMapping("/login")
  public Integer login(User u, HttpSession session) {

    Integer i = studentService.getUser(u, session);
    return i;

  }
  
  
  // 登陆
  @Override
  public Integer getUser(User u, HttpSession session) {
    // TODO Auto-generated method stub
    User u2 = studentMapper.getUser(u);
    if (u2 == null) {
      return 1;
    } else if (u2.getPassword() == null || !u2.getPassword().equals(u.getPassword())) {
      return 2;
    }
    session.setAttribute("username", u.getUsername());
    if (u2.getStatus() == 1) {
      return 3;
    } else if (u2.getStatus() == 2) {
      return 4;
    }
    return null;
  }

  */

}
